﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _37构造函数
{
    class Stud
    {

        //析构函数
        //当程序结束的时候  析构函数才执行
        //帮助我们释放资源
        //GC Garbage Collection
        ~Stud()
        {
            Console.WriteLine("析构函数");
        }


        //字段，属性，方法，构造函数
        public Stud(string name,int age,char sex,int str,int dou,int num)
        {
            this.Name = name;
            this.Age = age;
            this.Sex = sex;
            this.Str = str;
            this.Dou = dou;
            this.Num = num;
        }

        //this关键字
        public Stud(string name, int str, int dou, int num):this(name,0,'c',str, dou, num)
        {

        }


        public string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public int _age;       
        public int Age
        {
            get { return _age; }
            set
            {
                if (value < 0 || value > 100)
                {
                    value = 0;
                }
                _age = value; }
        }

        public char _sex;
        public char Sex
        {
            get { 
                if (_sex != '男' && _sex != '女')
                {
                   return _sex = '男';
                }
                return _sex; }
            set { _sex = value; }
        }

        public int _str;
        public int Str
        {
            get { return _str; }
            set { _str = value; }
        }

        public int _dou;
        public int Dou
        {
            get { return _dou; }
            set { _dou = value; }
        }

        public int _num;
        public int Num
        {
            get { return _num; }
            set { _num = value; }
        }
        public void Say() 
        {
            Console.WriteLine("我叫{0},今年{1}岁了,我是{2}生", this.Name, this.Age, this.Sex);
        }

        public void Show()
        {
            Console.WriteLine("我的总成绩是{0}，平均成绩是{1}",this.Str+this.Dou+this.Num,(this.Str + this.Dou + this.Num/3));
        }
    }
}
